package com.src;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.GridView;
import android.widget.Toast;

//对于事件监听
//全局性与非全局性
//控件的事件监听优先于全局的事件监听

public class DividerActivity extends Activity {
	// private GridView gridView = null;
	private Handler handler = null;
	private Message message = new Message();
	private int id = message.what;
	private final static int ONE = 0;
	private final static int TWO = 1;
	private final static int THREE = 2;
	private final static int FOUR = 3;

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case 19:
			handler.sendEmptyMessage(ONE);
			break;
		case 20:
			handler.sendEmptyMessage(TWO);
			break;
		case 21:
			handler.sendEmptyMessage(THREE);
			break;
		case 22:
			handler.sendEmptyMessage(FOUR);
			break;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				if (id == ONE) {
					Toast.makeText(DividerActivity.this, "ONE",
							Toast.LENGTH_SHORT);
					System.out.println("ONE");
				} else if (id == TWO) {
					Toast.makeText(DividerActivity.this, "TWO",
							Toast.LENGTH_SHORT);
					System.out.println("TWO");
				} else if (id == THREE) {
					Toast.makeText(DividerActivity.this, "THREE",
							Toast.LENGTH_SHORT);
					System.out.println("THREE");
				} else if (id == FOUR) {
					Toast.makeText(DividerActivity.this, "FOUR",
							Toast.LENGTH_SHORT);
					System.out.println("FOUR");
				} else {
					Toast.makeText(DividerActivity.this, "NULL",
							Toast.LENGTH_SHORT);

				}
				super.handleMessage(msg);
			}

		};

	}
}